//
//  CSSectionIcon.m
//  市场监管通
//
//  Created by 网新中研 on 16/4/18.
//  Copyright © 2016年 centralsoft. All rights reserved.
//

#import "CSSectionIcon.h"
#import "Common.h"
#import "CS_Page_SectionTitleView.h"
#import "CS_Page_DescriptionView.h"
#import "CS_Page_SpaceView.h"
#import "CSPageElementModel.h"

@interface CSSectionIcon()

@property (nonatomic, strong) UIView *seperatorLine;
@property (nonatomic, strong) CS_Page_SectionTitleView *page_SectionTitleView;
@property (nonatomic, strong) CS_Page_DescriptionView *page_descriptionView;

@end

@implementation CSSectionIcon

-(NSInteger)viewType{
    return CSViewType_PageSectionTitleView;
}

+(instancetype)sectionIcon:(NSString *)title color:(UIColor *)color{
    
    
    
    CSSectionIcon *sectionIcon = [CSSectionIcon new];
    sectionIcon.page_SectionTitleView = [CS_Page_SectionTitleView page_SectionTitleView:title color:color image:nil];
//    sectionIcon.page_descriptionView = [CS_Page_DescriptionView descriptionViewWithTitle:title content:nil];
    return sectionIcon;
    
    
    sectionIcon.title = title;
    sectionIcon.color = color;
    
    return sectionIcon;
}

-(CGFloat)layoutView:(UIView *)superView primaryY:(CGFloat)primaryY{
    
    return [self.page_SectionTitleView layoutView:superView primaryY:primaryY];
    
    
    UIView *rectangleView = [UIView new];
    rectangleView.frame = CGRectMake(10.0, CELL_CONTENT_MARGIN_HEIGHT, 5, 20);
    rectangleView.backgroundColor = self.color;
    
    UILabel *label = [UILabel new];
    label.font = [UIFont systemFontOfSize:17.0];
    label.textColor = COLOR_TEXT_3;
    label.text = self.title;
    label.numberOfLines = 0;
    
    //最终label所需要的高度
    CGFloat finalHeight = [self estimateHeight:label.text font:label.font width:kWindowW - CELL_SEPERATOR_MARGIN_LEFT - CELL_RIGHT_MARGIN];
    
    finalHeight = finalHeight > 20.0 ? finalHeight : 20.0;
    
    label.frame = CGRectMake(CELL_SEPERATOR_MARGIN_LEFT + 10.0 + 5.0, CELL_CONTENT_MARGIN_HEIGHT, kWindowW - CELL_SEPERATOR_MARGIN_LEFT - CELL_RIGHT_MARGIN, finalHeight);
    
    self.seperatorLine.frame = CGRectMake(0, finalHeight + CELL_CONTENT_MARGIN_HEIGHT + CELL_CONTENT_MARGIN_HEIGHT, kWindowW, CELL_SEPERATOR_LINE_HEIGHT);
    
    
    
    [self addSubview:rectangleView];
    [self addSubview:label];
    [self addSubview:self.seperatorLine];
    self.backgroundColor = [UIColor whiteColor];
    self.frame = CGRectMake(0, primaryY, 0, CELL_CONTENT_MARGIN_HEIGHT + CELL_CONTENT_MARGIN_HEIGHT + finalHeight + CELL_SEPERATOR_LINE_HEIGHT);
    
    [superView addSubview:self];
    
    return primaryY + CELL_CONTENT_MARGIN_HEIGHT + CELL_CONTENT_MARGIN_HEIGHT + finalHeight + CELL_SEPERATOR_LINE_HEIGHT+1;
}

- (UIView *)seperatorLine {
	if(_seperatorLine == nil) {
		_seperatorLine = [[UIView alloc] init];
        STYLE_SEPERATOR_LINE(_seperatorLine);
	}
	return _seperatorLine;
}

@end
